package com.xyq.system.controller.sysuer;


import com.xyq.common.core.constants.HttpConstants;
import com.xyq.common.core.controller.BaseController;
import com.xyq.common.core.domain.Result;
import com.xyq.system.domain.sysuser.dto.LoginDTO;
import com.xyq.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员用户管理接口")
public class SysUserController extends BaseController {

    @Autowired
    private ISysUserService userService ;

    @ApiResponse(responseCode = "3103" ,description = "用户名或密码错误")
    @ApiResponse(responseCode = "1000" , description = "操作成功")
    @ApiResponse(responseCode = "3102" ,description = "用户不存在")
    @Parameter(name = "password" , in = ParameterIn.QUERY , description = "密码")
    @Parameter(name = "userAccount" ,in = ParameterIn.QUERY , description = "用户账号")
    @Operation(summary = "登录" ,  description = "根据用户名和密码来登录")
    @PostMapping("/login")
    public Result<String>  login(@RequestBody LoginDTO loginDTO){
        return userService.login(loginDTO.getUserAccount() , loginDTO.getPassword()) ;
    }
    @GetMapping("/info")    // 获取响应中的header里的值
    public Result info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return userService.info(token);
    }
    @DeleteMapping("/logout")
    public Result logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toResult( userService.logout(token) );
    }
    @PostMapping("/addUser")
    public Result add(@RequestBody LoginDTO loginDTO){
        return toResult( userService.add(loginDTO.getUserAccount() , loginDTO.getPassword())) ;
    }



}
